package com.dhc.service.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

/**
 * @Author kazu
 * @Date 2023/10/07 23:24
 * @Version 1.0
 */
@SuppressWarnings({"all"})
@Component
public class SendEmailCode {
	
	@Autowired
	private JavaMailSender javaMailSender;
	
	@Value("${spring.mail.username}")
	private String fromEmail;
	
	/**
	 * 发送文本邮件
	 *
	 * @param to      收件人
	 * @param subject 标题
	 * @param content 正文
	 * @throws MessagingException
	 */
	public void sendEmailCode(String to, String subject, String content) {
		SimpleMailMessage message = new SimpleMailMessage();
		message.setFrom(fromEmail);
		message.setTo(to);
		message.setSubject(subject);
		message.setText(content);
		javaMailSender.send(message);
	}

}
